package com.accp.vehiclecare.action.hzaction;

import com.accp.vehiclecare.biz.hzbiz.HzBiz;
import com.accp.vehiclecare.pojo.Enginetype;
import com.accp.vehiclecare.vo.hzvo.Incometype;
import com.accp.vehiclecare.vo.hzvo.Serviceitem;
import com.accp.vehiclecare.vo.hzvo.Serviceitemtype;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/pp") // 命名空间
public class HzAction {
    @Autowired
    private HzBiz ppbiz;

    @GetMapping("{p}/{s}")
    public PageInfo<Enginetype> queryPage(@PathVariable Integer p, @PathVariable Integer s) throws Exception {
        return ppbiz.showListpp(p,s);
    }
    @GetMapping("show")
    public List<Serviceitemtype> queryOn2() throws Exception {
        return ppbiz.Query();
    }
    @GetMapping("One/{id}")
    public Enginetype queryOne(@PathVariable Integer id) throws Exception {
        return ppbiz.QueryOnepp(id);
    }
    @DeleteMapping("del/{pid}")
    public Map<String, Object> deletePersonById(@PathVariable Integer pid) {
        ppbiz.RemovePP(pid);
        Map<String, Object> message = new HashMap<String, Object>();
        message.put("code", "200");
        message.put("msg", "ok");
        return message;
    }
    @PostMapping("add")
    public Map<String, Object> addPerson(@RequestBody Enginetype enginetype) {
        ppbiz.AddPP(enginetype);
        Map<String, Object> message = new HashMap<String, Object>();
        message.put("code", "200");
        message.put("msg", "ok");
        return message;
    }
    @PutMapping("update/{id}")
    public Map<String, Object> update(@RequestBody Enginetype enginetype,@PathVariable Integer id) {
        ppbiz.updatepp(enginetype,id);
        Map<String, Object> message = new HashMap<String, Object>();
        message.put("code", "200");
        message.put("msg", "ok");
        return message;
    }
    @GetMapping("byOne/{id}")
    public List<Serviceitem> queryOneServiceitem(@PathVariable Integer id) throws Exception {
        return ppbiz.QueryServiceitembyid(id);
    }
    @DeleteMapping("del2/{id}")
    public Map<String, Object> deletePersonById2(@PathVariable Integer id) {
        System.out.println(id+"---------------");
        ppbiz.DeleteServiceitem(id);
        Map<String, Object> message = new HashMap<String, Object>();
        message.put("code", "200");
        message.put("msg", "ok");
        return message;
    }
    @GetMapping("list2")
    public List<Incometype> showlist() throws Exception {
        System.out.println("-----------");
        return ppbiz.list();
    }
    @PostMapping("add2")
    public Map<String, Object> addPerson2(@RequestBody Serviceitem serviceitem){
        ppbiz.addServiceitem(serviceitem);
        Map<String, Object> message = new HashMap<String, Object>();
        message.put("code", "200");
        message.put("msg", "ok");
        return message;
    }
    @GetMapping("list3/{id}")
    public Serviceitem QueryOne(@PathVariable Integer id) throws Exception {
        return ppbiz.QueryOneServiceitem(id);
    }
    @PutMapping("update2/{id}")
    public Map<String, Object> update2(@RequestBody Serviceitem serviceitem,@PathVariable Integer id) {
        ppbiz.updateOneServiceitem(serviceitem,id);
        Map<String, Object> message = new HashMap<String, Object>();
        message.put("code", "200");
        message.put("msg", "ok");
        return message;
    }
}
